<?php
/**
 * 用户进入程序控制器
 * User：LLW
 * Data：2020-03-23
 */

namespace app\api\controller;

use app\api\model\LoginModel;
use app\api\model\UserModel;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Login extends Controller
{
    public function __construct(Request $request = null)
    {
        parent::__construct();
        $this->login = new LoginModel();
        $this->user = new UserModel();
    }

    /**
     *用户登录
     * @throws \think\Exception
     */
    public function Login()
    {
        $res = $this->login->postLogin();
        return $res;
    }

    /**
     * 用户注册
     * return json
     */
    public function Register()
    {
        if(input('post.')){
            $res = $this->login->postRegister();
            return $res;
        }
        $phone = input('phone',null);
        if($phone){
            AjaxReturn(1,'ok',$phone);
        }else{
            AjaxReturn(1,'ok',1);
        }
    }
    /**
     * 忘记密码
     */
    public function Backpwd()
    {
        $res = $this->login->postPwd();
        return $res;
    }
    /**
     * 发送短信
     * @param $phone 发送用户
     * return json
     */
    public function Send()
    {
        $phone = input('us_phone');

        $res = $this->login->Sendmsg($phone,1);

        if($res['code'] > 0){
            AjaxReturn(1,$res['msg']);
        }else{
            AjaxReturn(-1,$res['msg']);
        }
    }

    /**
     * 退出登录
     */
    public function LoginOut()
    {
        Session::set('uid','');
        AjaxReturn(1,'退出成功');
    }
}